package com.soboot.log.utils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @Author:
 * @createTime: 2022年09月20日 14:33:07
 * @version:
 * @Description:
 * @Copyright:
 */
@Component
public class LogUtil{

    private static String applicationEnv;
    private static String applicationName;
    private static String applicationPort;

    @Value("${spring.cloud.nacos.discovery.namespace:dev}")
    public void setApplicationEnv(String appEnv){
        LogUtil.applicationEnv = appEnv;
    }

    @Value("${spring.application.name}")
    public void setApplicationName(String appName){
        LogUtil.applicationName = appName;
    }

    @Value("${server.port}")
    public void setApplicationPort(String appPort){
        LogUtil.applicationPort = appPort;
    }

    public static void trace(String msg) {
        getLogger().trace(msg);
    }
    public static void trace(String msg,Throwable t) {
        getLogger().trace(msg,t);
    }

    public static void debug(String msg) {
        getLogger().debug(msg);
    }
    public static void debug(String msg,Throwable t) {
        getLogger().debug(msg,t);
    }
    public static void debug(String msg, Object var1) {
        getLogger().debug(msg, var1);
    }
    public static void debug(String msg, Object var1,Object var2) {
        getLogger().debug(msg, var1, var2);
    }
    public static void debug(String msg, Object var1,Object var2,Object var3) {
        getLogger().debug(msg, var1,var2,var3);
    }
    public static void debug(String msg, Object var1,Object var2,Object var3,Object var4) {
        getLogger().info(msg, var1,var2,var3,var4);
    }

    public static void info(String msg) {
        getLogger().info(msg);
    }
    public static void info(String msg, Object var1) {
        getLogger().info(msg, var1);
    }
    public static void info(String msg, Object var1,Object var2) {
        getLogger().info(msg, var1, var2);
    }
    public static void info(String msg, Object var1,Object var2,Object var3) {
        getLogger().info(msg, var1,var2,var3);
    }
    public static void info(String msg, Object var1,Object var2,Object var3,Object var4) {
        getLogger().info(msg, var1,var2,var3,var4);
    }
    public static void warn(String msg) {
        getLogger().warn(msg);
    }
    public static void warn(String msg,Throwable t) {
        getLogger().warn(msg,t);
    }

    public static void error(String msg) {
        getLogger().error(msg);
    }

    public static void error(String msg,Throwable t) {
        getLogger().error(msg,t);
    }
    public static void error(String msg, Object var1) {
        getLogger().error(msg, var1);
    }

    private static Logger getLogger() {
        return LogManager.getLogger(applicationEnv + "-" + applicationName +"-"+applicationPort);
    }
}
